<template>
  <LeftBar :options="menuList"></LeftBar>
</template>
<script>
import { mapState } from "vuex";
import LeftBar from "./LeftBar.vue";
import * as menuAPI from "@/api/menu";

export default {
  name: "leftMenu",
  components: {
    LeftBar,
  },
  data() {
    return {
      menuList: [],
    };
  },
  computed: { ...mapState(["hasUnreadRelay"]) },
  watch: {
    hasUnreadRelay(val) {
      console.log(val, "sssssss");
    },
  },
  methods: {},
  created() {
    // 菜单数据
    // this.menuList = JSON.parse(sessionStorage.getItem("userInfo")).menus
    /* this.menuList = [
      {
        icon: "xxzybqgl-icon",
        id: "0",
        ismenu: 1,
        levels: 1,
        name: "首页",
        num: 0,
        parentId: "0",
        url: "/home",
      },
      {
        icon: "xxzybqgl-icon",
        id: "2",
        ismenu: 1,
        levels: 1,
        name: "待办事项",
        num: 0,
        parentId: "0",
        url: "/todo/todo",
      },
      {
        icon: "xxzygl-icon",
        id: "3",
        ismenu: 1,
        levels: 1,
        name: "案件查办",
        num: 1,
        parentId: "0",
        url: "",
        children: [
          {
            icon: "",
            id: "3",
            ismenu: 1,
            levels: 2,
            name: "受理阶段",
            num: 1,
            parentId: "197",
            url: "/workOrder/accepted",
          },
          {
            icon: "",
            id: "4",
            ismenu: 1,
            levels: 2,
            name: "查办阶段",
            num: 1,
            parentId: "197",
            url: "/workOrder/process",
          },
          {
            icon: "",
            id: "4",
            ismenu: 1,
            levels: 2,
            name: "结案阶段",
            num: 1,
            parentId: "197",
            url: "/workOrder/appraise",
          },
        ],
      },
      {
        icon: "xxzygl-icon",
        id: "1",
        ismenu: 1,
        levels: 1,
        name: "案件管理",
        num: 1,
        parentId: "0",
        url: "",
        children: [
          {
            icon: "",
            id: "2",
            ismenu: 1,
            levels: 2,
            name: "查询中心",
            num: 1,
            parentId: "197",
            url: "/workOrder/all",
          },
        ],
      },
      {
        icon: "xxzybqgl-icon",
        id: "2",
        ismenu: 1,
        levels: 1,
        name: "分析中心",
        num: 0,
        parentId: "0",
        url: "/statistics/statistics/home",
      },
      {
        icon: "xxzybqgl-icon",
        id: "2",
        ismenu: 1,
        levels: 1,
        name: "审批中心",
        num: 0,
        parentId: "0",
        url: "/workOrder/approval",
      },
      {
        icon: "xtgl-icon",
        id: "7",
        ismenu: 1,
        levels: 1,
        name: "系统管理",
        num: 1,
        parentId: "0",
        url: "",
        children: [
          // 原本是俩页面现在合成一个
          {
            icon: "",
            id: "11",
            ismenu: 1,
            levels: 2,
            name: "行政区划管理",
            num: 1,
            parentId: "197",
            url: "/system/administrativeDivision",
          },
          {
            icon: "",
            id: "10",
            ismenu: 1,
            levels: 2,
            name: "组织机构管理",
            num: 1,
            parentId: "197",
            url: "/system/organization",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "用户管理",
            num: 1,
            parentId: "199",
            url: "/system/userManage",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "个人信息管理",
            num: 1,
            parentId: "199",
            url: "/system/userInfoManage",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "系统通知",
            num: 1,
            parentId: "199",
            url: "/system/userInfoManage1",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "短信日志",
            num: 1,
            parentId: "199",
            url: "/system/message",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "事项管理",
            num: 1,
            parentId: "200",
            url: "/matters/matters",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "行业领域管理",
            num: 1,
            parentId: "197",
            url: "/system/vocation",
          },
          {
            icon: "",
            id: "8",
            ismenu: 1,
            levels: 2,
            name: "数据字典管理",
            num: 1,
            parentId: "197",
            url: "/system/dict",
          },
          {
            icon: "",
            id: "9",
            ismenu: 1,
            levels: 2,
            name: "回复模板管理",
            num: 1,
            parentId: "197",
            url: "/system/cardTemplate",
          },
          {
            icon: "",
            id: "9",
            ismenu: 1,
            levels: 2,
            name: "全局配置项管理",
            num: 1,
            parentId: "197",
            url: "/system/configure",
          },
          {
            icon: "",
            id: "9",
            ismenu: 1,
            levels: 2,
            name: "部门配置项管理",
            num: 1,
            parentId: "197",
            url: "/system/departmentConfigure",
          },
          {
            icon: "",
            id: "9",
            ismenu: 1,
            levels: 2,
            name: "页面信息管理",
            num: 1,
            parentId: "197",
            url: "/system/pageInfoManage",
          },
          {
            icon: "",
            id: "10",
            ismenu: 1,
            levels: 2,
            name: "节假日管理",
            num: 1,
            parentId: "198",
            url: "/system/holidayManage",
          },
        ],
      },
    ]; */
    /* this.menuList = [
      {
        children: [
          {
            children: "",
            icon: "",
            id: "202",
            ismenu: 1,
            levels: 2,
            name: "信息资源注册",
            num: 1,
            parentId: "197",
            url: "/xaddResourceBasic",
          },
          {
            children: "",
            icon: "",
            id: "203",
            ismenu: 1,
            levels: 2,
            name: "信息资源审核",
            num: 3,
            parentId: "197",
            url: "/xaddResourceBasic/check",
          },
          {
            children: "",
            icon: "",
            id: "280",
            ismenu: 1,
            levels: 2,
            name: "信息资源总览",
            num: 8,
            parentId: "197",
            url: "/xaddResourceBasic/overview",
          },
        ],
        icon: "xxzygl-icon",
        id: "197",
        ismenu: 1,
        levels: 1,
        name: "信息资源管理",
        num: 1,
        parentId: "0",
        url: "",
      },
      {
        children: [
          {
            children: "",
            icon: "",
            id: "205",
            ismenu: 1,
            levels: 2,
            name: "标签库管理",
            num: 1,
            parentId: "199",
            url: "/labelManage/taglibManage",
          },
          {
            children: "",
            icon: "",
            id: "206",
            ismenu: 1,
            levels: 2,
            name: "标签管理",
            num: 3,
            parentId: "199",
            url: "/labelManage/tagsManage",
          },
        ],
        icon: "xxzybqgl-icon",
        id: "199",
        ismenu: 1,
        levels: 1,
        name: "信息资源标签管理",
        num: 2,
        parentId: "0",
        url: "",
      },
      {
        children: [
          {
            children: "",
            icon: "",
            id: "204",
            ismenu: 1,
            levels: 2,
            name: "数据资源挂接配置",
            num: 1,
            parentId: "198",
            url: "/dataResourceManage/xaddResourceProbe",
          },
          {
            children: "",
            icon: "",
            id: "235",
            ismenu: 1,
            levels: 2,
            name: "数据资源挂接同步",
            num: 2,
            parentId: "198",
            url: "/dataResourceManage/xaddResourceSync",
          },
          {
            children: "",
            icon: "",
            id: "274",
            ismenu: 1,
            levels: 2,
            name: "数据服务挂接同步",
            num: 3,
            parentId: "198",
            url: "/dataResourceManage/xaddDataResourceSync",
          },
        ],
        icon: "xxzygzgl-icon",
        id: "198",
        ismenu: 1,
        levels: 1,
        name: "信息资源挂接管理",
        num: 3,
        parentId: "0",
        url: "",
      },
      {
        children: [
          {
            children: "",
            icon: "",
            id: "233",
            ismenu: 1,
            levels: 2,
            name: "信息资源多态展现",
            num: 1,
            parentId: "230",
            url: "/xaddResourceShow",
          },
          {
            children: "",
            icon: "",
            id: "232",
            ismenu: 1,
            levels: 2,
            name: "目录多模态呈现",
            num: 2,
            parentId: "230",
            url: "/multimodal",
          },
          {
            children: "",
            icon: "",
            id: "231",
            ismenu: 1,
            levels: 2,
            name: "目录统计分析与关联图谱",
            num: 3,
            parentId: "230",
            url: "/associationMap",
          },
          {
            children: "",
            icon: "",
            id: "234",
            ismenu: 1,
            levels: 2,
            name: "相似度分析",
            num: 4,
            parentId: "230",
            url: "/multimodal/cosine",
          },
        ],
        icon: "xxzydtzx-icon",
        id: "230",
        ismenu: 1,
        levels: 1,
        name: "信息资源多态展现",
        num: 4,
        parentId: "0",
        url: "",
      },
      {
        children: [
          {
            children: "",
            icon: "",
            id: "106",
            ismenu: 1,
            levels: 2,
            name: "用户管理",
            num: 1,
            parentId: "105",
            url: "/sysManage/userManage",
          },
          {
            children: "",
            icon: "",
            id: "114",
            ismenu: 1,
            levels: 2,
            name: "角色管理",
            num: 2,
            parentId: "105",
            url: "/sysManage/roleManage",
          },
          {
            children: "",
            icon: "",
            id: "119",
            ismenu: 1,
            levels: 2,
            name: "菜单管理",
            num: 4,
            parentId: "105",
            url: "/sysManage/menuManage",
          },
          {
            children: "",
            icon: "",
            id: "141",
            ismenu: 1,
            levels: 2,
            name: "通知管理",
            num: 9,
            parentId: "105",
            url: "/sysManage/noticeManage",
          },
          {
            children: "",
            icon: "",
            id: "284",
            ismenu: 1,
            levels: 2,
            name: "数据申请管理",
            num: 34,
            parentId: "105",
            url: "/sysManage/dataApplicationManage",
          },
        ],
        icon: "xtgl-icon",
        id: "105",
        ismenu: 1,
        levels: 1,
        name: "系统管理",
        num: 7,
        parentId: "0",
        url: "",
      },
      {
        children: [
          {
            children: "",
            icon: "",
            id: "283",
            ismenu: 1,
            levels: 2,
            name: "我的消息",
            num: 1,
            parentId: "282",
            url: "/personal/news",
          },
          {
            children: "",
            icon: "",
            id: "285",
            ismenu: 1,
            levels: 2,
            name: "我的数据申请",
            num: 2,
            parentId: "282",
            url: "/personal/dataApply",
          },
        ],
        icon: "grzx-icon",
        id: "282",
        ismenu: 1,
        levels: 1,
        name: "个人中心",
        num: 7,
        parentId: "0",
        url: "",
      },
      {
        children: [
          {
            children: "",
            icon: "",
            id: "128",
            ismenu: 1,
            levels: 2,
            name: "业务日志",
            num: 6,
            parentId: "172",
            url: "/logManage/businessLog",
          },
          {
            children: "",
            icon: "",
            id: "133",
            ismenu: 1,
            levels: 2,
            name: "登录日志",
            num: 6,
            parentId: "172",
            url: "/logManage/loginLog",
          },
        ],
        icon: "rzgl-icon",
        id: "172",
        ismenu: 1,
        levels: 1,
        name: "日志管理",
        num: 8,
        parentId: "0",
        url: "",
      },
      {
        children: "",
        icon: "sjzd-icon",
        id: "266",
        ismenu: 1,
        levels: 1,
        name: "数据字典",
        num: 10,
        parentId: "0",
        url: "/dataDictionary",
      },
    ]; */
    /*  if (this.menuList[0].children[0]) {
      this.$router.push({ path: this.menuList[0].children[0].url });
      localStorage.setItem("firstPath", this.menuList[0].children[0].url);
    } else {
      this.$router.push({ path: this.menuList[0].url });
      localStorage.setItem("firstPath", this.menuList[0].url);
    } */
    menuAPI.tree().then((res) => {
      const list = res.result;
      const tree = [];
      const currentPath = this.$route.path;
      let hasPermission = false; // 判断当前页面是否有权限

      if (list.length === 0) {
        this.$router.replace("noPermission");
        return;
      }

      /* for (const node1 of list) {
        if (node1.levels === "1") {
          node1.children = [];
          for (const node2 of list) {
            if (node1.id === node2.parentId) {
              node1.children.push(node2);
            }
          }
          if (node1.children.length === 0) delete node1.children;
          tree.push(node1);
        }

        if (currentPath === node1.url) {
          hasPermission = true;
        }
      }

      if (!hasPermission && !["/portals", "/404", "noPermission"].find((item) => currentPath.indexOf(item) > -1)) {
        const path = tree[0].url ? tree[0].url : tree[0].children[0].url;
        this.$router.push(path);
      } */
      this.menuList = list;
    });
  },
  mounted() {},
};
</script>
<style lang="less" scoped></style>
